<?PHP
session_start();
include("common/connect.php");
include("common/common.php");

function GetTbId( $tbid )
{
	return $tbid;
}

if( !isset($_SESSION["user"]) ) 
{
	$url = "Location:login.php?ref=view_discount.php";
	header($url);
}

$showtype = trim(CheckUrlParamNoDie( "showtype" ));
$input_tradeid = trim(CheckUrlParamNoDie( "input_tradeid" ));
$tradeid_begin = substr($input_tradeid, 0, 6);
$tradeid_end = substr($input_tradeid, -4);
$nPage = SetUrlParamInt("page");
$opt = CheckUrlParamNoDie("opt");
$id = CheckUrlParamNoDie("id");
if( $nPage < 0 )
	$nPage = 0;

if ($opt == "reset")
{
	$sql = "update report_items set handle_code = 0,operater='' where id=".$id." limit 1";
	$result = mysql_query( $sql );
	if (mysql_affected_rows() == 0)
		echo "<script>alert('操作失败！');";
		
	echo "<script>window.history.back()</script>";
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
<!--
body,td,th {
	font-family: 宋体;
	font-size: 13px;
	color: #000;
}
body {
	background-color: #FFF;
}
.STYLE1 {
	font-size: x-large;
	font-weight: bold;
}
-->
</style>
<script language="javascript">
function OnFind()
{
	var input_tradeid = document.getElementById("input_tradeid").value;
	window.location.href= "view_discount.php?input_tradeid=" + input_tradeid ;
}
</script>
</head>

<body>
<!--<a href="add_trade.php?opt=add">添加记录</a>-->
<div align="center" class="STYLE1">淘客数据处理后台</div>
<br>
<table align="center">
	<tr>
    	<td>订单号:<input type="text" onclick="javascript:select();" value="<?PHP echo $input_tradeid; ?>" id="input_tradeid" size="20"/>
    <input type="button" onclick="javascript:OnFind();" value="查找" />&nbsp;&nbsp;
	<a href="view_discount.php?page=0&showtype=<?PHP echo $showtype; ?>">首页</a>&nbsp;&nbsp;
	<a href="view_discount.php?input_tradeid=<?PHP echo $input_tradeid; ?>&page=<?PHP echo $nPage - 1; ?>">
		<?PHP if ($nPage > 0) echo "<a href='view_discount.php?input_tradeid=".$input_tradeid."&page=".($nPage - 1)."&showtype=".$showtype."'>上一页</a>"; ?>&nbsp;&nbsp;    
	<a href="view_discount.php?input_tradeid=<?PHP echo $input_tradeid; ?>&page=<?PHP echo $nPage + 1; ?>&showtype=<?PHP echo $showtype; ?>">下一页</a>		&nbsp;&nbsp;&nbsp;&nbsp;
    <a href="view_discount.php?showtype=lost">查看漏单</a>
    &nbsp;&nbsp;
    <a href="view_discount.php">默认显示</a>&nbsp;&nbsp;
    <a href="view_discount.php?showtype=deal">显示已处理</a>&nbsp;&nbsp;

	</td>
   </tr>
</table>

<table cellpadding="0" cellspacing="0" border="1" align="center">
	<tr>
    	<td height="25" width="50" align="center">序列号</td>
        <td width="200" align="center">时间</td>
        <td width="166" align="center">支付宝帐号</td>
   	  <td width="121" align="center">订单号</td>
      <td width="167" 	align="center">商品名称</td>
      <td width="167" 	align="center">商品ID</td>
      <td width="136" align="center">佣金</td>
      <td width="143" align="center">操作</td>
    </tr>
<?php

$limit = " limit ". $nPage*20 .",20";
if ($input_tradeid)
{
	$sql = "select * from report_items where trade_id like '".$tradeid_begin."%".$tradeid_end."' order by id desc";
}
else
{
	if ($showtype == "lost")
		$sql = "select * from report_items where handle_code = 3 order by id desc".$limit;
	else if ($showtype == "deal")
		$sql = "select * from report_items where handle_code = 2 order by id desc".$limit;
	else
		$sql = "select * from report_items where handle_code = 0 or handle_code = 1 order by id desc".$limit;
}
	
//$sql = "select * from report_items";
//$sql = "select * from trade where has_return=0".$search."order by id desc".$limit;
	
$result = mysql_query( $sql );
while( $result && $row = mysql_fetch_assoc( $result ))
{
	$use_discount = "否";
?>
<tr <?PHP if ($row["handle_code"] == 1) echo "bgcolor='#CC9966'"; else if ($row["handle_code"] == 2) echo "bgcolor='#33CC66'"; else if ($row["handle_code"] == 3) echo "bgcolor='#CC3333'";?> >
    <td height="25" width="50" align="center" style="color:<?PHP if ($row["a_no"]==1) echo "#0000CC"; else if ($row["a_no"]==2) echo "#CC0000";?>" > <?PHP echo $row["id"]; ?></td>
    <td width="200" align="center" title="<?PHP echo $row["opt_time"]; ?>"><?PHP echo $row["pay_time"]; ?></td>
	<td width="166" align="center"><?PHP echo $row["outer_code"]; ?>&nbsp;</td>
	<td width="121" 	align="center" title="<?PHP echo $row["pay_price"]."元  实际成交额：".$row["real_pay_fee"]; ?>"><?PHP echo $row["trade_id"]; ?>&nbsp;</td>
	<td width="167" align="center" title="<?PHP echo $row["num_iid"]; ?>"><?PHP echo $row["item_title"]; ?>&nbsp;</td>
    <td width="167" align="center" title="<?PHP echo $row["item_num"]."件"; ?>"><?PHP echo $row["num_iid"]; ?>&nbsp;</td>
	<td width="136" align="center" title="<?PHP echo ($row["commission_rate"] * 100)."%"; ?>"><?PHP echo $row["commission"]; ?>&nbsp;</td>
	<td width="143" align="center" title="<?PHP echo "操作人：".$row["operater"]; ?>"><?PHP if ($row["handle_code"] == 0) { ?><a href="deal_trade.php?id=<?PHP echo $row["id"]; ?>&tbid=<?PHP echo GetTbId($row["outer_code"]); ?>&tradeid=<?PHP echo $row["trade_id"]; ?>">操作</a>&nbsp;<?PHP } ?>
    <?PHP if ($row["handle_code"] == 1 || $row["handle_code"] == 3) echo "<a href='view_discount.php?id=".$row["id"]."&opt=reset'>重置</a>"; ?>
    <?PHP if ($row["handle_code"] == 2) echo "<a href='view_trade.php?id=".$row["id"]."&tradeid=".$row["trade_id"]."'>查看</a>"; ?>
    </td>
</tr>
<?PHP
}
?>
</table>

</body>
</html>
